package com.example.shardingspheredemo.commons.generator;

import com.example.shardingspheredemo.commons.utils.SnowflakeIdUtil;
import lombok.Data;
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;

import java.util.Properties;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author Andrew Yang
 * @className SimpleShardingKeyGenerator
 * @description
 * @package com.example.shardingspheredemo.commons.generator
 * @create 2020-09-10 16:14
 */
@Data
public class SimpleShardingKeyGenerator implements ShardingKeyGenerator {

    private AtomicLong atomic = new AtomicLong(0);
    private Properties properties = new Properties();

    @Override
    public Comparable<?> generateKey() {
//        return atomic.incrementAndGet();
        SnowflakeIdUtil snowflakeIdUtil = new SnowflakeIdUtil();
        return snowflakeIdUtil.nextId();
    }

    @Override
    public String getType() {
        //声明类型
        return "SIMPLE";
    }
}

